<template>
  <view class="da1">
    <!--    导航栏-->
    <view style="height: 60px"></view>
    <view class="da11">
      <view class="da12" @click="all(item)" v-for="(item,index) in list1" :key="index">
        <text>{{ item.query_val === '全部' ? obj.type || item.query_val : item.query_val }}</text>
        <image src="/static/other/shaixuan-jiantou.png" v-if="item.query_val==='全部'"></image>
        <image src="/static/other/shaixuan.png" v-else></image>
      </view>
    </view>
    <!--    模态框-->
    <view class="all" v-show="show2">
      <view class="allbox">
        <view class="allboxbody" v-for="(item,index) in list1[0].filter_val" :key="index" @click="sub(item)">{{
            item
          }}
        </view>
      </view>
    </view>
<!--    <page-container>-->

<!--    </page-container>-->
    <!--    内容-->
    <view class="da2">
      <view class="da21" v-for="(item,index) in list" :key="index" @click="go(item._id)">
        <view class="text" style="font-size: 23px">{{ item.title }}</view>
        <view class="da22">
          <image :src="item.image"></image>
          <view class="da23">
            <view class="text">{{ item.be_suit }}</view>
            <view class="text" style="color:#d0d0d0;margin-top: 10px">{{ item.describe }}</view>
          </view>
        </view>
        <view class="price">
          <view>已约{{ item.sales }}</view>
          <view>￥{{ item.price }}</view>
        </view>
      </view>
    </view>

    <view style="height: 200px"></view>
  </view>
</template>

<script>
import {physget, phyquery, phyterm} from "../../utils/API/homeapi";

export default {
  data() {
    return {
      list: [],
      list1: [],
      obj: {
        type: "",
        sales: "desc",
        price: "desc"
      },
      //全部
      show2: false,

    };
  },
  methods: {
    async xuan() {
      let {data} = await physget()
      this.list = data
    },
    async xuan1() {
      let {data} = await phyterm()
      this.list1 = data
    },
    //点击全部
    async sub(item) {
      this.obj.type = item
      this.show2 = !this.show2
      this.set()
    },
    async set() {
      let {data} = await phyquery(this.obj)
      this.list = data
    },
    //跳转详情
    go(id) {
      wx.navigateTo({
        url: '/pages/physicallist/physicallist?id=' + id
      })
    },
    //点击排行
    async all(item) {
      if (item.query_val === "销量") {
        this.obj.sales = this.obj.sales === "desc" ? 'asc' : 'desc'
        await this.set()
      } else if (item.query_val === "价格") {
        this.obj.price = this.obj.price === "desc" ? 'asc' : 'desc'
        await this.set()
      } else {
        //全部
        this.show2 = !this.show2
      }

    }
  },
  mounted() {
    this.xuan()
    this.xuan1()
  }
}
</script>

<style lang="scss" scoped>
.da1 {
  .da11 {
    width: 100%;
    height: 60px;
    box-sizing: border-box;
    background-color: #fff;
    display: flex;
    position: fixed;
    top: 0;
    left: 0;

    .da12 {
      flex: 1;
      text-align: center;
      line-height: 60px;
      display: flex;
      align-items: center;
      justify-content: center;

      image {
        margin-left: 5px;
        width: 15px;
        height: 15px;
      }
    }
  }

  .da2 {
    width: 100%;
    background-color: #fafafa;

    .da21 {
      margin: 10px auto;
      width: 96%;
      height: 230px;
      background-color: #fff;
      z-index: 999;

      .price {
        color: red;
        font-weight: 700;
        //font-size: 20px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        height: 50px;
        padding: 0 3px;
      }

      .text {
        font-weight: 700;
      }

      .da22 {
        width: 100%;
        height: 150px;
        background-color: #ffffff;
        display: flex;
        justify-content: space-between;
        align-items: center;

        .da23 {
          width: 220px;
          background-color: #ffffff;
          height: 100%;
        }
      }

      image {
        width: 120px;
        height: 120px;
      }
    }
  }
}

.all {
  width: 100%;
  height: 100%;
  background-color: rgba(66, 56, 56, 0.7);
  position: fixed;
  top: 60px;
  left: 0;

  .allbox {
    width: 100%;
    height: 280px;
    background-color: #fff;

    .allboxbody {
      width: 100%;
      height: 40px;
      //border: 1px solid;
      padding-left: 35px;
      line-height: 40px;
    }
  }
}
</style>
